package com.xinpu.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.xinpu.entity.TCompanyRole;
import com.xinpu.service.ITCompanyRoleService;
import com.xinpu.vo.ResponseMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * CompanyRoleController
 *
 * @author ayuan
 * @date 2021/5/21
 */
@RestController
@RequestMapping("/companyRole")
public class CompanyRoleController {


    @Autowired
    private ITCompanyRoleService itCompanyRoleService;

    /**
     * 角色列表
     *
     * @return
     */
    @GetMapping("/list")
    public ResponseMessage list() {
        return ResponseMessage.ok(itCompanyRoleService.list());
    }

    /**
     * 创建或编辑企业角色
     *
     * @param map
     * @return
     */
    @PostMapping("/createOrEdit")
    public ResponseMessage createOrEdit(@RequestBody Map<String, String> map) {
        TCompanyRole tRole = new TCompanyRole();
        String id = map.get("id");
        if (StringUtils.isNotBlank(id)) {
            tRole.setId(Integer.parseInt(id));
        }
        tRole.setName(map.get("name"));
        tRole.setMarked(map.get("marked"));
        tRole.setInfo(map.get("info"));
        itCompanyRoleService.saveOrUpdate(tRole);
        return ResponseMessage.ok();
    }

    /**
     * 删除角色
     *
     * @param map
     * @return
     */
    @PostMapping("/delete")
    public ResponseMessage delete(@RequestBody Map<String, String> map) {
        itCompanyRoleService.removeById(map.get("id"));
        return ResponseMessage.ok();
    }


}
